package com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonCodeEnum;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonResult;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.entity.req.*;
import com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.service.SmsWnsRegistrationProcessDetailService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.Future;

/**
 * <p>
 * 报到流程步骤表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-01-08
 */
@RestController
@SecretBody
@RequestMapping("/welcomeNewStudent/processDetail")
public class SmsWnsRegistrationProcessDetailController {
    @Resource
    private SmsWnsRegistrationProcessDetailService smsWnsRegistrationProcessDetailService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiOperation("入学办理事项完成情况")
    @GetMapping("/stuEnrollmentStatus")
    public ResponseResult listProcess(HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsWnsRegistrationProcessDetailService.stuEnrollmentStatus(userId);
    }

    @ApiOperation("展示某年级所有专业")
    @GetMapping("/listAllMajorByGrade")
    public ResponseResult listAllMajorByGrade(@RequestParam("grade") String grade) { // 年级
        return smsWnsRegistrationProcessDetailService.listAllMajorByGrade(grade);
    }

    @ApiOperation("展示某年级所有班级")
    @GetMapping("/listAllClassByGrade")
    public ResponseResult listAllClassByGrade(@RequestParam("grade") String grade) { // 年级
        return smsWnsRegistrationProcessDetailService.listAllClassByGrade(grade);
    }

    @ApiOperation("展示某年级所有专业学生结构")
    @GetMapping("/listStuNumByGrade")
    public ResponseResult listStuNumByGrade(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                            @RequestParam(value = "collegeId", required = false) String collegeId, // 学院id
                                            @RequestParam(value = "majorId", required = false) String majorId, // 专业id
                                            @RequestParam("grade") String grade) { // 年级
        return smsWnsRegistrationProcessDetailService.listStuNumByGrade(pageNum, pageSize, collegeId, majorId, grade);
    }

    @ApiOperation("展示某专业某年级班级信息")
    @GetMapping("/listClassByGrade")
    public ResponseResult listClassByGrade(@RequestParam("grade") String grade, // 年级
                                           @RequestParam("majorId") String majorId) { // 专业id
        return smsWnsRegistrationProcessDetailService.listClassByGrade(grade, majorId);
    }

    @ApiOperation("展示某专业学生信息")
    @GetMapping("/listStuInfoByMajor")
    public ResponseResult listStuInfoByGrade(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                             @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                             @RequestParam("gradeId") String gradeId, // 某专业下的年级id
                                             @RequestParam(value = "classId", required = false) Integer classId) { // 班级id
        return smsWnsRegistrationProcessDetailService.listStuInfoByMajor(pageNum, pageSize, gradeId, classId);
    }

    @ApiOperation(value = "新生信息批量导入")
    @PostMapping("/newStu/batch/add")
    public ResponseResult batchAddStuInfo(@RequestBody SmsWnsNewStuBatchAddReq newStuBatchAddReq, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        ResponseResult commonCodeEnum;
        try {
            Future<ResponseResult> future = smsWnsRegistrationProcessDetailService.batchAddStuInfo(newStuBatchAddReq, userId);
            while (true) {
                if (future.isDone()) {
                    commonCodeEnum = future.get();
                    break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed(CommonCodeEnum.FAIL);
        }
        return commonCodeEnum;
    }

    @ApiOperation("新生批量删除")
    @PostMapping("/delNewStu")
    public ResponseResult delNewStu(@RequestBody SmsWnsIdListReq idListReq) {
        return smsWnsRegistrationProcessDetailService.delNewStu(idListReq);
    }

    @ApiOperation("专业分班")
    @PostMapping("/classifyStu")
    public ResponseResult classifyStu(@RequestBody ClassifyStuReq classifyStuReq) {
        return smsWnsRegistrationProcessDetailService.classifyStu(classifyStuReq);
    }

    @ApiOperation("批量转班")
    @PostMapping("/changeClass")
    public ResponseResult changeClass(@RequestBody ChangeClassReq changeClassReq) {
        return smsWnsRegistrationProcessDetailService.changeClass(changeClassReq);
    }

    @ApiOperation("转班记录列表")
    @GetMapping("/stuOrgUpdateHistoryList")
    public ResponseResult stuOrgUpdateHistoryList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                  @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                  @RequestParam(value = "searchStr", required = false) String searchStr) {
        return smsWnsRegistrationProcessDetailService.stuOrgUpdateHistoryList(pageNum, pageSize, searchStr);
    }

    @ApiOperation("查看某学生转班记录")
    @GetMapping("/stuOrgUpdateHistoryListByUserId")
    public ResponseResult stuOrgUpdateHistoryListByUserId(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                          @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                          @RequestParam(value = "userId") String userId) {
        return smsWnsRegistrationProcessDetailService.stuOrgUpdateHistoryListByUserId(pageNum, pageSize, userId);
    }

    // 个人信息采集情况
    @ApiOperation("个人信息采集情况")
    @GetMapping("/getPersonalInfoStatus")
    public ResponseResult getPersonalInfoStatus(HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsWnsRegistrationProcessDetailService.getPersonalInfoStatus(userId);
    }

    // 迎新报道流程
    // 1.招生就业处报道
    // 教师小程序
    @ApiOperation("展示新生信息")
    @GetMapping("/listNewStuInfo")
    public ResponseResult listNewStuInfo(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                         @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                         @RequestParam(value = "searchStr", required = false) String searchStr) {
        return smsWnsRegistrationProcessDetailService.listNewStuInfo(pageNum, pageSize, searchStr);
    }

    @ApiOperation("新生信息详情")
    @GetMapping("/newStuInfoDetail")
    public ResponseResult newStuInfoDetail(@RequestParam("userId") String userId) {
        return smsWnsRegistrationProcessDetailService.newStuInfoDetail(userId);
    }

    @ApiOperation("上传现场照片")
    @PostMapping("/uploadSitePic")
    public ResponseResult uploadSitePic(@RequestBody SmsWnsStudentCardInformationReq cardInformationReq) {
        return smsWnsRegistrationProcessDetailService.uploadSitePic(cardInformationReq);
    }

    // 招生就业处后台
    @ApiOperation("通过身份证号获取新生三证信息")
    @GetMapping("/newStuInfoDetailByIdCard")
    public ResponseResult newStuInfoDetailByIdCard(@RequestParam("idCard") String idCard) {
        return smsWnsRegistrationProcessDetailService.newStuInfoDetailByIdCard(idCard);
    }

    @ApiOperation("审核三证信息")
    @PostMapping("/approveNewStuInfo")
    public ResponseResult approveNewStuInfo(@RequestBody SmsWnsStudentCardInformationReq cardInformationReq) {
        return smsWnsRegistrationProcessDetailService.approveNewStuInfo(cardInformationReq);
    }

    @ApiOperation(value = "学生学籍照片批量导入")
    @PostMapping("/batch/addChsiPic")
    public ResponseResult batchAddChsiPic(@RequestBody SmsWnsChsiPicBatchAddReq req, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        ResponseResult commonCodeEnum;
        try {
            Future<ResponseResult> future = smsWnsRegistrationProcessDetailService.batchAddChsiPic(req, userId);
            while (true) {
                if (future.isDone()) {
                    commonCodeEnum = future.get();
                    break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed(CommonCodeEnum.FAIL);
        }
        return commonCodeEnum;
    }

    // 公共
    @ApiOperation("扫描二维码报道成功")
    @PostMapping("/reportSuccess")
    public ResponseResult reportSuccess(@RequestBody SmsWnsRegistrationProcessReq req) {
        return smsWnsRegistrationProcessDetailService.reportSuccess(req);
    }

    @ApiOperation("修改某流程报道状态")
    @PostMapping("/updDetailStatus")
    public ResponseResult updDetailStatus(@RequestBody SmsWnsRegistrationProcessDetailReq req) {
        return smsWnsRegistrationProcessDetailService.updDetailStatus(req);
    }

    @ApiOperation("学生清单")
    @GetMapping("/stuInfoList")
    public ResponseResult stuInfoList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                      @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                      @RequestParam(value = "orgId", required = false) Integer orgId,
                                      @RequestParam(value = "stuStatus", required = false) String stuStatus,
                                      @RequestParam("sort") Integer sort, // 流程顺序
                                      @RequestParam(value = "status", required = false) Integer status, // 步骤状态
                                      @RequestParam(value = "searchStr", required = false) String searchStr) {
        return smsWnsRegistrationProcessDetailService.stuInfoList(pageNum, pageSize, orgId, stuStatus, sort, status, searchStr);
    }

    @ApiOperation("学生信息详情")
    @GetMapping("/stuInfoDetail")
    public ResponseResult stuInfoDetail(@RequestParam("stuId") String stuId,
                                        @RequestParam("sort") Integer sort) { // 流程顺序
        return smsWnsRegistrationProcessDetailService.stuInfoDetail(stuId, sort);
    }

}

